package net.arvin.dao;

import java.util.List;

import net.arvin.mobilebanksystem.R;
import net.arvin.model.Card;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class BindCardsAdapter extends BaseAdapter {
	private List<Card> mCards;
	private LayoutInflater mInflater;

	public BindCardsAdapter(List<Card> cardsInfo, Context context) {
		this.mInflater = LayoutInflater.from(context);
		this.mCards = cardsInfo;
	}

	@Override
	public int getCount() {
		return this.mCards.size();
	}

	@Override
	public Object getItem(int position) {
		return mCards.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		CardsInfoHolder holder = null;
		if(convertView == null){
			convertView = mInflater.inflate(R.layout.listitem_bindcard, null);
			holder = new CardsInfoHolder();
			holder.cardBank = (TextView) convertView.findViewById(R.id.cardbank);
			holder.cardSubNum = (TextView) convertView.findViewById(R.id.cardSubNum);
			holder.cardType = (TextView) convertView.findViewById(R.id.cardtype);
			convertView.setTag(holder);
		}else{
			holder = (CardsInfoHolder) convertView.getTag();
		}
		holder.cardBank.setText(mCards.get(position).getCardbank());
		holder.cardSubNum.setText(mCards.get(position).getCardnumber().substring(5));
		holder.cardType.setText(mCards.get(position).getCardtype());
		return convertView;
	}
	
	private class CardsInfoHolder{
		public TextView cardBank;
		public TextView cardSubNum;
		public TextView cardType;
	}

}
